
#include "game_controller\headers\game_controller_level.hpp"

#include "game_controller\headers\game_controller_scene.hpp"

namespace GameController {


Level::Level()
{
}


Level::~Level()
{
}


void
Level::addObject( GameModel::IObject::Ptr _object )
{
	m_objects.insert( _object );
}


void
Level::setBackground( QImage* _back )
{
	m_background = _back;
}


const QImage*
Level::getBackground() const
{
	return m_background;
}


std::shared_ptr< IScene >
Level::formScene( std::shared_ptr< GameModel::IDistanceUnit > _from, std::shared_ptr< GameModel::IDistanceUnit > _to )
{
	std::shared_ptr< IScene > newScene( new Scene( getBackground() ) );

	ObjectsConstIterator it( m_objects.begin() ), end( m_objects.end() );

	for( ; it != end; ++it )
	{
		if(	( ( *it )->getCurrentLocation().getHorizontalLocation() >= *_from ) && ( ( *it )->getCurrentLocation().getHorizontalLocation() <= *_to ) )
			newScene->addObject( *it );
	}

	return newScene;
}


ILevel::ObjectsContainer&
Level::getObjects()
{
	return m_objects;
}


ILevel::ObjectsContainer const&
Level::getObjects() const
{
	return m_objects;	
}


} // namespace GameController